import 'link_mode_model.dart';
import 'device_category_display_model.dart';

class ThingSmartDeviceCategoryModel {
  String? icon;

  ///< Device icon
  String? name;

  ///< Device name
  String? activatorDes;

  ///< Protocol type: wifi, zigbee, bluetooth, etc.
  String? pid;

  ///< Device product Id
  String? sale;

  ///< Used to interactively display 'Coming Soon', returns if there is one, or null if there isn't one.
  bool enableLead;

  ///< Whether to support detailed guidance
  ThingSmartDeviceCategoryDisplayModel? display;
  List<ThingSmartALinkModeModel>? linkModes;

  bool nProcess;

  ///< Whether EZ/AP process, otherwise mixed process
  bool fromFeedback;

  ///< Process after feedback

  String? manualUrl;

  /// Instruction manual link
  int? manualType;

  /// 0 - no product eBrochure, 1 - single step product eBrochure, 2 - multi-step product eBrochure, 3 - single and multi-step product eBrochure.

  // To be deleted
  int? capability;
  String? category;

  ThingSmartDeviceCategoryModel({
    this.icon,
    this.name,
    this.activatorDes,
    this.pid,
    this.sale,
    this.enableLead = false,
    this.display,
    this.linkModes,
    this.nProcess = false,
    this.fromFeedback = false,
    this.manualUrl,
    this.manualType,
    this.capability,
    this.category,
  });
factory ThingSmartDeviceCategoryModel.fromJson(Map<String, dynamic> json) {
  // 处理 display 字段
  final ThingSmartDeviceCategoryDisplayModel? display;
  if (json['display'] != null) {
    final displayJson = json['display'] is Map<String, dynamic> 
        ? json['display'] as Map<String, dynamic>
        : (json['display'] as Map).cast<String, dynamic>();
    display = ThingSmartDeviceCategoryDisplayModel.fromJson(displayJson);
  } else {
    display = null;
  }

  // 处理 linkModes 字段
  final List<ThingSmartALinkModeModel>? linkModes;
  if (json['linkModes'] != null) {
    linkModes = (json['linkModes'] as List).map((i) {
      final linkModeJson = i is Map<String, dynamic> 
          ? i 
          : Map<String, dynamic>.from(i as Map<dynamic, dynamic>);
      return ThingSmartALinkModeModel.fromJson(linkModeJson);
    }).toList();
  } else {
    linkModes = null;
  }

  return ThingSmartDeviceCategoryModel(
    icon: json['icon'],
    name: json['name'],
    activatorDes: json['activatorDes'],
    pid: json['pid'],
    sale: json['sale'],
    enableLead: json['enableLead'] ?? false,
    display: display,
    linkModes: linkModes,
    nProcess: json['nProcess'] ?? false,
    fromFeedback: json['fromFeedback'] ?? false,
    manualUrl: json['manualUrl'],
    manualType: json['manualType'],
    capability: json['capability'],
    category: json['category'],
  );
}

  Map<String, dynamic> toJson() {
    return {
      'icon': icon,
      'name': name,
      'activatorDes': activatorDes,
      'pid': pid,
      'sale': sale,
      'enableLead': enableLead,
      'display': display?.toJson(),
      'linkModes': linkModes?.map((e) => e.toJson()).toList(),
      'nProcess': nProcess,
      'fromFeedback': fromFeedback,
      'manualUrl': manualUrl,
      'manualType': manualType,
      'capability': capability,
      'category': category,
    };
  }
}
